package com.atguigu.gmall.item.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

/**
 * @Author 刘嘉乐
 * @Date 2022/1/14 16:33
 * @Version 1.0
 */

@Configuration
public class ThreadPoolConfig {
    @Bean
    public ExecutorService executorService(
            @Value("${threadPool.corePoolSize}")Integer corePoolSize,
            @Value("${threadPool.maximumPoolSize}")Integer maximumPoolSize,
            @Value("${threadPool.keepAliveTime}")Integer keepAliveTime,
            @Value("${threadPool.blockingQueueSize}")Integer blockingQueueSize
     ){
        return new ThreadPoolExecutor(corePoolSize,maximumPoolSize,
        keepAliveTime,TimeUnit.SECONDS,new ArrayBlockingQueue<>(blockingQueueSize));

    }
}
